<template>
  <div @dblclick="gobackVideoGridPages">
    <video-player
      class="video-player vjs-custom-skin"
      ref="videoPlayer"
      :playsinline="true"
      :options="playerOptions"
      @play="onPlayerPlay($event)"
      @pause="onPlayerPause($event)"
    ></video-player>
  </div>
</template>

<script>
// 视频
import "vue-video-player/src/custom-theme.css";
import "videojs-flash";
//import default_poster from "@/components/myvideo/default_poster.png";
import {mapActions} from 'vuex'

export default {
  name: "myVideoRTMP",
  props: {
    src: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      playerOptions: {
        sources: [
          {
            type: "rtmp/mp4",
            src: this.src
          }
        ],
        autoplay: true, // 自动播放
        fluid: true, // 按比例缩放适应容器
        muted: true, // 消除所有音频。
        //poster: default_poster, // 封面
        techOrder: ["flash"],
        aspectRatio: "16:9", // 画面比例
        // controls: false, // 控制条
        // controlBar: {
        //   timeDivider: true,
        //   durationDisplay: true,
        //   remainingTimeDisplay: false,
        //   fullscreenToggle: true
        // },
        // preload: "auto", // 预加载
        // loop: false, // 循环播放
        notSupportedMessage: "此视频暂无法播放，请稍后再试",
        // language: "zh-CN", // 语言
        // playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        flash: {
          // hls: { withCredentials: false },
          swf: 'https://cdn.bootcss.com/videojs-swf/5.4.2/video-js.swf' // 引入静态文件swf
        },
        // html5: { hls: { withCredentials: false } }
      }
    };
  },
  watch: {
    src: {
      deep: true,
      handler() {
        //console.log("监控视频地址：", this.src);

        this.playerOptions.sources[0].src = this.src;
      }
    }
  },
  mounted() {},
  computed: {
    player() {
      return this.$refs.videoPlayer.player;
    }
  },
  methods: {
    ...mapActions([
      'closeDetailsLoadVideoGridPages'
    ]),
    gobackVideoGridPages() {
      this.closeDetailsLoadVideoGridPages()
    },
    onPlayerPlay() {
      // console.log("player play!", player);
    },
    onPlayerPause() {
      // console.log("player pause!", player);
    }
  }
};
</script>
